function loadComments() {
    this.source = null;
    this.start = function () {
        this.source = new EventSource("/3");
        this.source.addEventListener("message", function (event) {
            console.log(event.data);
            document.getElementById("test").innerText = event.data;
        });
        this.source.onerror = function () {
            this.close();
        };
    };

    this.stop = function () {
        this.source.close();
    }
}

comment = new loadComments();
window.onload = function () {
    comment.start();
};
window.onbeforeunload = function () {
    comment.stop();
}
